﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
/*
using MySql.Data.MySqlClient;
using Oracle.DataAccess.Client;
*/
using System.Data;

namespace DatabaseExtension
{
    public static class DbTypeConverter
    {
        private static Dictionary<Type, DbType> DbTypes = new Dictionary<Type, DbType>()
        {
            {typeof(Int64),DbType.Int64},
            {typeof(Byte[]), DbType.Binary},
            {typeof(Boolean), DbType.Boolean},
            {typeof(String), DbType.String},
            {typeof(Char[]), DbType.String},
            {typeof(DateTime),DbType.DateTime},
            {typeof(DateTimeOffset), DbType.DateTimeOffset},
            {typeof(TimeSpan), DbType.Time},
            {typeof(Decimal), DbType.Decimal},
            {typeof(Double), DbType.Double},
            {typeof(Image), DbType.Binary},
            {typeof(Int32), DbType.Int32},
            {typeof(Single), DbType.Single},
            {typeof(Int16), DbType.Int16},
            {typeof(Object), DbType.Object},
            {typeof(Byte), DbType.Byte},
            {typeof(SByte), DbType.SByte},
            {typeof(Guid), DbType.Guid},
            {typeof(UInt16), DbType.UInt16},
            {typeof(UInt32), DbType.UInt32},
            {typeof(UInt64), DbType.UInt64}
        };

        public static DbType ToDbType(Object value)
        {
            var t = value.GetType();
            if (DbTypeConverter.DbTypes.ContainsKey(t) == false)
                throw new NotImplementedException();
            return DbTypeConverter.DbTypes[t];
        }
        /*
        private static Dictionary<Type, Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>> DbTypes = new Dictionary<Type, Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>>()
        {
            {typeof(Int64), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Int64, SqlDbType.BigInt, OracleDbType.Int64, MySqlDbType.Int64)},
            {typeof(Byte[]), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Binary, SqlDbType.VarBinary, OracleDbType.Blob, MySqlDbType.LongBlob)},
            {typeof(Boolean), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Boolean, SqlDbType.Bit, OracleDbType.Int16, MySqlDbType.Bit)},
            {typeof(String), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.String, SqlDbType.NVarChar, OracleDbType.NVarchar2, MySqlDbType.String)},
            {typeof(Char[]), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.String, SqlDbType.NVarChar, OracleDbType.NVarchar2, MySqlDbType.String)},
            {typeof(DateTime),new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.DateTime, SqlDbType.DateTime, OracleDbType.Date, MySqlDbType.DateTime)},
            {typeof(DateTimeOffset), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.DateTimeOffset, SqlDbType.DateTimeOffset, OracleDbType.IntervalDS, MySqlDbType.DateTime)},
            {typeof(TimeSpan), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Time, SqlDbType.Time, OracleDbType.IntervalDS, MySqlDbType.Time)},
            {typeof(Decimal), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Decimal, SqlDbType.Decimal, OracleDbType.Decimal, MySqlDbType.Decimal)},
            {typeof(Double), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Double, SqlDbType.Float, OracleDbType.Double, MySqlDbType.Double)},
            {typeof(Image), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbTFinanzamtype>(DbType.Binary, SqlDbType.VarBinary, OracleDbType.Blob, MySqlDbType.LongBlob)},
            {typeof(Int32), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Int32, SqlDbType.Int, OracleDbType.Int32, MySqlDbType.Int32)},
            {typeof(Single), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Single, SqlDbType.Real, OracleDbType.Single, MySqlDbType.Float)},
            {typeof(Int16), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Int16, SqlDbType.SmallInt, OracleDbType.Int16, MySqlDbType.Int16)},
            {typeof(Object), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Object, SqlDbType.Variant, OracleDbType.Object, MySqlDbType.Blob)},
            {typeof(Byte), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Byte, SqlDbType.TinyInt, OracleDbType.Byte, MySqlDbType.UByte)},
            {typeof(SByte), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.SByte, SqlDbType.TinyInt, OracleDbType.Byte, MySqlDbType.Byte)},
            {typeof(Guid), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.Guid, SqlDbType.UniqueIdentifier, OracleDbType.Varchar2, MySqlDbType.Guid)},
            {typeof(UInt16), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.UInt16, SqlDbType.Int, OracleDbType.Int32, MySqlDbType.UInt16)},
            {typeof(UInt32), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.UInt32, SqlDbType.BigInt, OracleDbType.Int64, MySqlDbType.UInt32)},
            {typeof(UInt64), new Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType>(DbType.UInt64, SqlDbType.Real, OracleDbType.Single, MySqlDbType.UInt64)}

        };

        public static Tuple<DbType, SqlDbType, OracleDbType, MySqlDbType> ToDbType(Object value)
        {
            var t = value.GetType();
            if (DbTypeConverter.DbTypes.ContainsKey(t) == false)
                throw new NotImplementedException();
            return DbTypeConverter.DbTypes[t];
        }
         * */
    }
}
